import Number from '@/components/Number';

const groupNameColumn = {
  id: 'groupName',
  dataIndex: 'groupName',
  title: '名称',
  width: 150,
};

const tagDescriptionColumn = {
  id: 'description',
  dataIndex: 'description',
  title: '标签定义',
  width: 200,
};

const accuratyColumn = {
  id: 'accuracy',
  dataIndex: 'accuracy',
  title: '准确度',
  width: 200,
};

const createdByColumn = {
  id: 'created',
  dataIndex: 'created',
  title: '创建人',
  width: 200,
};

const coverageColumn = {
  id: 'coverage',
  dataIndex: 'coverage',
  title: '覆盖人数',
  width: 100,
  render: (data) => <Number showTip format="short" value={data} />,
};

const operationColumn = {
  id: 'operation',
  dataIndex: 'operation',
  title: '操作',
};

export const getColumnsByType = (type, operationRender, isMine) => {
  // 智能拓展标签类型有不同的column
  let columns;
  if (type === 1) {
    columns = [
      groupNameColumn,
      accuratyColumn,
      createdByColumn,
      { ...operationColumn, render: operationRender },
    ];
  } else if (type === 2) {
    columns = [
      groupNameColumn,
      accuratyColumn,
      { ...operationColumn, render: operationRender },
    ];
  } else if (type === 'crowd') {
    columns = [
      {
        title: '人群ID',
        dataIndex: 'id',
      },
      {
        title: '人群名称',
        dataIndex: 'name',
      },
      { ...operationColumn, render: operationRender },
    ];
  } else if (type === 'extend_crowd') {
    columns = [
      {
        dataIndex: 'extend_crowd_id',
        title: '拓展人群ID',
      },
      {
        title: '拓展人群名称',
        dataIndex: 'crowd_name',
      },
      !isMine && {
        title: '创建人',
        dataIndex: 'created',
        width: 120,
      },
      { ...operationColumn, render: operationRender },
    ];
  } else {
    columns = [
      groupNameColumn,
      tagDescriptionColumn,
      coverageColumn,
      { ...operationColumn, render: operationRender },
    ];
  }
  return columns;
};

export const MIN_CONFIDENCE = 0.5;
export const MAX_CONFIDENCE = 0.99;
export const DEFAULT_CONFIDENCE = MIN_CONFIDENCE;
//导出人群标签
export const crowdOptions = [
  {
    dimName: '我的人群',
    id: 'mine',
    type: 0,
  },
  {
    dimName: '所有人群',
    id: 'list',
    type: 0,
  },
  {
    dimName: '我的拓展人群',
    id: 'extend/list_info?',
    type: 0,
  },
  {
    dimName: '所有拓展人群',
    id: 'extend/list_info',
    type: 0,
  },
];
//导出扩展人群置信度
export const getGroupTagInfo = (groupTagsInfo, isExtend) => {
  const {
    coverage,
    created,
    name,
    id,
    confidence,
    extend_crowd_id,
    background,
    minCoverage,
    crowd_name,
  } = groupTagsInfo;
  return !isExtend
    ? {
        coverage,
        created,
        customType: 3,
        groupId: id,
        groupName: name,
      }
    : {
        coverage,
        created,
        crowdId: extend_crowd_id,
        customType: 2,
        description: background,
        accuracy: confidence,
        minCoverage,
        groupName: crowd_name,
      };
};
